package com.example.node.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.Request;
import com.bumptech.glide.request.target.SizeReadyCallback;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.example.node.listener.OnGlideBitmapListener;

public class GlideUtils {

    private static OnGlideBitmapListener onGlideBitmapListener;

    //标准的方式方法
    public static void loadImageView(Context mContext, String url, ImageView imageView) {
        Glide.with(mContext).load(url).into(imageView);
    }

    //居中的加载方式
    public static void loadImageViewCenterCrop(Context mContext, String url, ImageView imageView) {
        Glide.with(mContext).load(url).centerCrop().into(imageView);
    }

    //加载Bitmap
    public static void loadBitmap(Context mContext, String url, OnGlideBitmapListener listener) {
        onGlideBitmapListener=listener;
        Glide.with(mContext).asBitmap().load(url).into(new Target<Bitmap>() {
            @Override
            public void onLoadStarted(@Nullable Drawable placeholder) {

            }

            @Override
            public void onLoadFailed(@Nullable Drawable errorDrawable) {

            }

            @Override
            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                onGlideBitmapListener.onResourceReady(resource);
            }

            @Override
            public void onLoadCleared(@Nullable Drawable placeholder) {

            }

            @Override
            public void getSize(@NonNull SizeReadyCallback cb) {

            }

            @Override
            public void removeCallback(@NonNull SizeReadyCallback cb) {

            }

            @Override
            public void setRequest(@Nullable Request request) {

            }

            @Nullable
            @Override
            public Request getRequest() {
                return null;
            }

            @Override
            public void onStart() {

            }

            @Override
            public void onStop() {

            }

            @Override
            public void onDestroy() {

            }
        });
    }
}
